package ace.module.account.core.impl.controller.rest.admin.ext;

import ace.cmp.core.model.R;
import ace.cmp.security.oauth2.resource.server.core.annotation.PreAuthorizeIsUserAuthenticated;
import ace.module.account.core.impl.dao.entity.IamAccountProfile;
import ace.module.account.core.impl.dao.repository.IamAccountProfileRepository;
import ace.module.account.core.impl.manager.IamAccountProfileManager;
import ace.module.security.api.AuthenticationApi;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 账户个人资料 admin controller.
 *
 * @author Caspar
 */
@Tag(name = "账户个人资料-管理-API")
@PreAuthorizeIsUserAuthenticated
@AllArgsConstructor
@RestController
@RequestMapping(IamAccountProfileExtAdminController.PATH)
@Valid
public class IamAccountProfileExtAdminController {

  public static final String PATH = "/account/iam-account-profile";
  private final IamAccountProfileManager iamAccountProfileManager;
  private final IamAccountProfileRepository iamAccountProfileRepository;
  private final AuthenticationApi authenticationApi;

  @GetMapping("/getByCurrentAccount")
  public R<IamAccountProfile> getByCurrentAccount() {
    Long accountId = authenticationApi.getAndCheckCurrentAccountId();
    IamAccountProfile iamAccountProfile =
        iamAccountProfileManager.getByAccountIdAndDeleteFlagIsFalse(accountId);
    return R.ok(iamAccountProfile);
  }
}
